/*
 * Copyright (c) 2018 maoyan.com
 * All rights reserved.
 *
 */
package com.darren.euc.repository;

import com.darren.euc.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 在这里编写类的功能描述
 *
 * @author fangwenhao
 * @created 2018/3/13
 */
public interface MemberRepository extends JpaRepository<Member,Integer> {

    List<Member> findByNameLike(String name);

    List<Member> findByIdIn(List<Integer> ids);

    List<Member> findByDeptId(Integer deptId);

    @Query("select count(*) from Member where deptId = ?1")
    Integer findCountByDeptId(Integer deptId);

    Member findByClientIdAndName(Integer clientId, String memberName);

    List<Member> findByClientId(Integer clientId);

    Member findByFaceUserId(Long faceUserId);

    List<Member> findByWristBandsNumber(String wristBandsNumber);
    @Query("select count(*) from Member where clientId = ?1 and employStatus in (?2)")
    Integer findByClientIdAndEmployStatusIn(Integer clientId, List<Integer> status);
    
    @Query(value = "SELECT COUNT(*) FROM euc_contracts as contract INNER JOIN euc_orders as roomorder on roomorder.id = contract.order_id INNER JOIN euc_member as member on member.client_id = roomorder.client_id  WHERE member.id = ?1  AND CURDATE() BETWEEN contract.contract_start_time AND contract.contract_end_time",nativeQuery = true)
    Integer findAvailableContractCount(Integer memberId);

    Member findByMobile(String mobile);
    
}
